Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New WPHookHelper utility class, incl PHP 8.0+ named param helper #2148

Merged
merged 3 commits into from
Dec 15, 2022

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Dec 14, 2022

Sniff: remove the $hookFunctions property

... as it is not currently used anywhere in the WPCS codebase.

Move "hook" related utilities to dedicated WPHookHelper

The "hook" related property is only used by a small set of sniffs, so are better placed in a dedicated class.

This commit moves the $hookInvokeFunctions property to a new WordPressCS\WordPress\Helpers\WPHookHelper class and starts using that class in the relevant sniffs.

Note:

  • The property is now private (and static).
  • Access to the property can be obtained via the new WPHookHelper::get_functions() method.
  • This new method can also pre-filter the list to only return those functions which are not specifically to invoke deprecated hooks.

Related to #1465

WPHookHelper: add new get_hook_name_param() method

... to support retrieving the hook name parameters from a stack of parameters, while supporting PHP 8.0+ function calls using named arguments.

This new method will be tested via the implementations in the ValidHookName and the PrefixAllGlobals sniffs (upcoming).

... as it is not currently used anywhere in the WPCS codebase.
The "hook" related property is only used by a small set of sniffs, so are better placed in a dedicated class.

This commit moves the `$hookInvokeFunctions` property to a new `WordPressCS\WordPress\Helpers\WPHookHelper` class and starts using that class in the relevant sniffs.

Note:
* The property is now `private` (and `static`).
* Access to the property can be obtained via the new `WPHookHelper::get_functions()` method.
* This new method can also pre-filter the list to only return thos functions which are not specifically to invoke deprecated hooks.

Related to 1465
... to support retrieving the hook name parameters from a stack of parameters, while supporting PHP 8.0+ function calls using named arguments.

This new method will be tested via the implementations in the `ValidHookName` and the `PrefixAllGlobals` sniffs.
WordPress/Helpers/WPHookHelper.php Show resolved Hide resolved
WordPress/Helpers/WPHookHelper.php Show resolved Hide resolved
Copy link
Member

@GaryJones GaryJones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GaryJones GaryJones merged commit 51b9e4e into develop Dec 15, 2022
@GaryJones GaryJones deleted the feature/new-wphookhelper-utility branch December 15, 2022 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants